package com.gcmm;

import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;

public class SimpleGlobalKeyListener implements NativeKeyListener {


    public void nativeKeyPressed(NativeKeyEvent e) {
        try {
            //获取输入字符
            String key = NativeKeyEvent.getKeyText(e.getKeyCode());

            switch (key) {
                // 开始/关闭鼠标连点
                case "Q":
                    if (Mouse.changeMouseState())
                        Mouse.continueClickAsync();
                    break;

                // 退出后台，结束程序
                case "W":
                    System.exit(0);
            }


        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }

    }

    public void nativeKeyReleased(NativeKeyEvent e) {
        System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
    }

    public void nativeKeyTyped(NativeKeyEvent e) {
        System.out.println("Key Typed: " + e.getKeyText(e.getKeyCode()));
    }


}
